<template>
  <div>
    <pic-upload v-model="bannerImagePath"></pic-upload>
    <div style="margin-top: 30px">
      <el-button type="primary" :loading="submitLoading" @click="uploadBanner">确定</el-button>
    </div>
  </div>
</template>

<script>
  import picUpload from '@/components/pic-upload'
  export default {
    name: 'index',
    components: {
      picUpload
    },
    data () {
      return {
        id: '',
        bannerImagePath: '',
        submitLoading: false
      }
    },
    mounted () {
      this.getBannerRequest()
    },

    methods: {
      getBannerRequest () {
        this.$http({
          url: this.$http.adornUrl('/rotation/chart/get'),
          method: 'get',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          console.log(data)
          this.bannerImagePath = data.picUrl
          this.id = data.id
        })
      },

      uploadBanner () {
        this.submitLoading = true
        this.$http({
          url: this.$http.adornUrl('/rotation/chart/update'),
          method: 'post',
          data: this.$http.adornData({
            id: this.id ? this.id : '',
            picUrl: this.bannerImagePath
          })
        }).then(({ res }) => {
          console.log(res)
          this.submitLoading = false
           this.$message.success('提交成功')
        })
      }
    }
  }
</script>

<style scoped>

</style>
